<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * ebsig接口操作类
 * @package  htdocs
 * @subpackage  module/eai
 * @author   allen.qiang
 * @version 1.0
 */

quanli_require('module/eai/crm.interface.php');

//加载会员账户类
quanli_include('module/base/customer/custAccount.class.php');

class ebsigEai implements crmInterface {

    /**
     * 查询会员所有账户科目信息
     * @param int $pcustID 会员号
     * @return array
     */
    public function searchCustAllAccount( $pcustID ) {

        if (!isset($pcustID) || !quanli_is_int($pcustID)) {
            return array( 'code' => 400, 'message' => '参数错误' );
        }

        //实例会员账户类
        $custAccount = new custAccount();

        //查询会员账户科目
        $args_array = array(
            'pcustID' => $pcustID
        );
        $subject_array = $custAccount->search( $args_array );
        if ($subject_array) {
            return array( 'code' => 200, 'message' => 'ok', 'data' => $subject_array );
        } else {
            return array( 'code' => 404, 'message' => '会员账户科目不存在' );
        }

    }

    /**
     * 查询会员账户科目
     * @param int $pcustID 会员号
     * @param int $subjectId 科目ID
     * @return mixed
     */
    public function searchCustAccount( $pcustID, $subjectId ) {

        if (!isset($pcustID, $subjectId) || !quanli_is_int($pcustID) || !quanli_is_int($subjectId)) {
            return array( 'code' => 400, 'message' => '参数错误' );
        }

        //实例会员账户类
        $custAccount = new custAccount();

        //查询会员账户科目
        $args_array = array(
            'pcustID' => $pcustID,
            'subjectId' => $subjectId
        );

        $subject_array = $custAccount->search( $args_array );
        if ($subject_array) {
            return array( 'code' => 200, 'message' => 'ok', 'data' => $subject_array[0] );
        } else {
            return array( 'code' => 404, 'message' => '会员账户科目不存在' );
        }

    }

    /**
     * 查询会员账户科目变更记录
     * @param int $pcustID 会员号
     * @param int $subjectId 科目ID
     * @param int $page 页码
     * @param int $rp 每页显示多少条数据
     * @param string $sortname 排序字段
     * @param string $sortorder 排序方式
     * @return array|mixed
     */
    public function searchCustAccountLog( $pcustID, $subjectId, $page, $rp, $sortname = null, $sortorder = null ) {

        if (!isset($pcustID, $subjectId) || !quanli_is_int($pcustID) || !quanli_is_int($subjectId)) {
            return array( 'code' => 400, 'message' => '参数错误' );
        }

        //实例会员账户类
        $custAccount = new custAccount();

        //查询会员账户科目
        $args_array = array(
            'pcustID' => $pcustID,
            'subjectId' => $subjectId,
            'page' => $page,
            'rp' => $rp,
            'sortname' => $sortname,
            'sortorder' => $sortorder
        );
        $subject_log_array = $custAccount->searchLog( $args_array );
        if ($subject_log_array) {
            return array( 'count' => $args_array['count'], 'data' => $subject_log_array );
        } else {
            return null;
        }

    }

    /**
     * 账户充值
     * @param array $args_array 充值参数
     * $args_array = array(
     *      'operator' => '操作人',
     *      'pcustID' => '会员号',
     *      'subjectId' => '科目ID',
     *      'amount' => '充值金额',
     *      'remark' => '备注',
     *      'externalTranCode' => '外部交易流水号'
     * )
     * @return array
     */
    public function recharge( $args_array ) {

        //实例会员账户类
        $custAccount = new custAccount();

        return $custAccount->recharge( $args_array );

    }

    /**
     * 账户扣减/消费
     * @param array $args_array 充值参数
     * $args_array = array(
     *      'operator' => '操作人',
     *      'pcustID' => '会员号',
     *      'subjectId' => '科目ID',
     *      'amount' => '扣减金额',
     *      'remark' => '备注',
     *      'externalTranCode' => '外部交易流水号'
     * )
     * @return array
     */
    public function deduction( $args_array ) {

        //实例会员账户类
        $custAccount = new custAccount();

        return $custAccount->deduction( $args_array );

    }

    /**
     * 账户冻结
     * @param array $args_array 充值参数
     * $args_array = array(
     *      'operator' => '操作人',
     *      'pcustID' => '会员号',
     *      'subjectId' => '科目ID',
     *      'amount' => '冻结金额',
     *      'remark' => '备注',
     *      'externalTranCode' => '外部交易流水号'
     * )
     * @return array
     */
    public function accountBlock( $args_array ){

        //实例会员账户类
        $custAccount = new custAccount();

        return $custAccount->accountBlock($args_array);

    }

    /**
     * 账户冻结回滚
     * @param array $args_array 充值参数
     * $args_array = array(
     *      'operator' => '操作人',
     *      'pcustID' => '会员号',
     *      'subjectId' => '科目ID',
     *      'amount' => '回滚金额',
     *      'remark' => '备注',
     *      'externalTranCode' => '外部交易流水号'
     * )
     * @return array
     */
    public function blockRollBack( $args_array ){

        //实例会员账户类
        $custAccount = new custAccount();

        return $custAccount->blockRollBack($args_array);

    }

    /**
     * 账户冻结扣减
     * @param array $args_array 充值参数
     * $args_array = array(
     *      'operator' => '操作人',
     *      'pcustID' => '会员号',
     *      'subjectId' => '科目ID',
     *      'amount' => '扣减金额',
     *      'remark' => '备注',
     *      'externalTranCode' => '外部交易流水号'
     * )
     * @return array
     */
    public function blockDeduction( $args_array ){

        //实例会员账户类
        $custAccount = new custAccount();

        return $custAccount->blockDeduction($args_array);

    }

}